package com.taobao.txc.client.aop;

import com.taobao.txc.client.aop.annotation.TxcTransaction;
import com.taobao.txc.common.LoggerInit;
import com.taobao.txc.common.LoggerWrap;
import com.taobao.txc.common.b.c;
import com.taobao.txc.common.config.ConsoleConfig;
import com.taobao.txc.common.config.i;
import com.taobao.txc.common.config.o;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.AdvisedSupport;
import org.springframework.aop.support.AopUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.ContextRefreshedEvent;

public class TxcTransactionScaner
  extends com.taobao.txc.common.d.b
{
  private static final LoggerWrap a = LoggerInit.logger;
  private static final Set<String> b = new HashSet();
  private b c;
  private String d = null;
  private String e = null;
  private int f = -1;
  private String g;
  private String h;
  private static final Set<String> i = new HashSet();
  private boolean j = false;
  
  public TxcTransactionScaner()
  {
    setOrder(2);
    setProxyTargetClass(true);
    try
    {
      if (i.d == null) {
        o.a(true);
      }
      this.j = o.a().b(System.getProperty("txc.servergroup") == null ? this.e : System.getProperty("txc.servergroup"));
      a.info((this.j ? "disable" : "enable") + " txc.");
    }
    catch (Exception localException) {}
    a.info("txc trasaction scaner initing.... use default client");
  }
  
  public TxcTransactionScaner(String paramString)
  {
    this(paramString, 1);
  }
  
  public TxcTransactionScaner(String paramString, int paramInt)
  {
    this(paramString, paramString, paramInt);
  }
  
  public TxcTransactionScaner(String paramString1, String paramString2)
  {
    this(paramString1, paramString2, 1);
  }
  
  public TxcTransactionScaner(String paramString1, String paramString2, int paramInt)
  {
    this(paramString1, paramString2, paramInt, null);
  }
  
  public TxcTransactionScaner(String paramString1, String paramString2, int paramInt, String paramString3)
  {
    setOrder(2);
    setProxyTargetClass(true);
    try
    {
      if (!StringUtils.isEmpty(paramString3))
      {
        new ConsoleConfig(paramString3);
        o.a(true);
      }
      else if (i.d == null)
      {
        o.a(true);
      }
      this.j = o.a().b(System.getProperty("txc.servergroup") == null ? this.e : System.getProperty("txc.servergroup"));
      a.info((this.j ? "disable" : "enable") + " txc.");
    }
    catch (Exception localException) {}
    this.d = paramString1;
    this.e = paramString2;
    this.f = paramInt;
    a.info("txc trasaction scaner initing...." + String.format("txcAppName:%s,txcServerGroup:%s,mode:%d", new Object[] { paramString1, this.e, Integer.valueOf(paramInt) }));
  }
  
  public TxcTransactionScaner(String paramString1, String paramString2, int paramInt1, int paramInt2)
  {
    this(paramString1, paramString2, paramInt1);
  }
  
  private void a()
  {
    if ((StringUtils.isEmpty(this.d)) || (StringUtils.isEmpty(this.e))) {
      throw new c("txcAppName or txcServerGroup is null", com.taobao.txc.common.b.b.i);
    }
    com.taobao.txc.client.a.a(this.d, this.e, this.f, i, this.g, this.h, 0);
  }
  
  /* Error */
  protected Object wrapIfNecessary(Object paramObject1, String paramString, Object paramObject2)
  {
    // Byte code:
    //   0: getstatic 52	com/taobao/txc/client/aop/TxcTransactionScaner:b	Ljava/util/Set;
    //   3: dup
    //   4: astore 4
    //   6: monitorenter
    //   7: getstatic 52	com/taobao/txc/client/aop/TxcTransactionScaner:b	Ljava/util/Set;
    //   10: aload_2
    //   11: invokeinterface 113 2 0
    //   16: ifeq +8 -> 24
    //   19: aload_1
    //   20: aload 4
    //   22: monitorexit
    //   23: areturn
    //   24: getstatic 52	com/taobao/txc/client/aop/TxcTransactionScaner:b	Ljava/util/Set;
    //   27: aload_2
    //   28: invokeinterface 112 2 0
    //   33: pop
    //   34: aload_0
    //   35: aload_1
    //   36: invokespecial 69	com/taobao/txc/client/aop/TxcTransactionScaner:a	(Ljava/lang/Object;)Ljava/lang/Class;
    //   39: astore 5
    //   41: aload 5
    //   43: invokevirtual 88	java/lang/Class:getMethods	()[Ljava/lang/reflect/Method;
    //   46: astore 6
    //   48: new 42	java/util/LinkedList
    //   51: dup
    //   52: invokespecial 103	java/util/LinkedList:<init>	()V
    //   55: astore 7
    //   57: aload 6
    //   59: astore 8
    //   61: aload 8
    //   63: arraylength
    //   64: istore 9
    //   66: iconst_0
    //   67: istore 10
    //   69: iload 10
    //   71: iload 9
    //   73: if_icmpge +68 -> 141
    //   76: aload 8
    //   78: iload 10
    //   80: aaload
    //   81: astore 11
    //   83: aload 11
    //   85: ldc 19
    //   87: invokevirtual 101	java/lang/reflect/Method:getAnnotation	(Ljava/lang/Class;)Ljava/lang/annotation/Annotation;
    //   90: checkcast 19	com/taobao/txc/client/aop/annotation/TxcTransaction
    //   93: astore 12
    //   95: aload 12
    //   97: ifnull +38 -> 135
    //   100: aload_0
    //   101: getfield 60	com/taobao/txc/client/aop/TxcTransactionScaner:j	Z
    //   104: ifne +31 -> 135
    //   107: aload 7
    //   109: aload_0
    //   110: aload 12
    //   112: aload 11
    //   114: invokespecial 70	com/taobao/txc/client/aop/TxcTransactionScaner:a	(Ljava/lang/Object;Ljava/lang/reflect/Method;)Lcom/taobao/txc/client/aop/a;
    //   117: invokevirtual 104	java/util/LinkedList:add	(Ljava/lang/Object;)Z
    //   120: pop
    //   121: getstatic 59	com/taobao/txc/client/aop/TxcTransactionScaner:i	Ljava/util/Set;
    //   124: aload 11
    //   126: invokestatic 86	com/taobao/txc/common/util/c/g:a	(Ljava/lang/reflect/Method;)Ljava/lang/String;
    //   129: invokeinterface 112 2 0
    //   134: pop
    //   135: iinc 10 1
    //   138: goto -69 -> 69
    //   141: aload 7
    //   143: invokevirtual 105	java/util/LinkedList:size	()I
    //   146: ifeq +19 -> 165
    //   149: aload_0
    //   150: new 20	com/taobao/txc/client/aop/b
    //   153: dup
    //   154: aload 7
    //   156: invokespecial 77	com/taobao/txc/client/aop/b:<init>	(Ljava/util/List;)V
    //   159: putfield 53	com/taobao/txc/client/aop/TxcTransactionScaner:c	Lcom/taobao/txc/client/aop/b;
    //   162: goto +8 -> 170
    //   165: aload_1
    //   166: aload 4
    //   168: monitorexit
    //   169: areturn
    //   170: aload_1
    //   171: invokestatic 109	org/springframework/aop/support/AopUtils:isAopProxy	(Ljava/lang/Object;)Z
    //   174: ifne +14 -> 188
    //   177: aload_0
    //   178: aload_1
    //   179: aload_2
    //   180: aload_3
    //   181: invokespecial 85	com/taobao/txc/common/d/b:wrapIfNecessary	(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
    //   184: astore_1
    //   185: goto +64 -> 249
    //   188: aload_0
    //   189: aload_1
    //   190: invokespecial 71	com/taobao/txc/client/aop/TxcTransactionScaner:b	(Ljava/lang/Object;)Lorg/springframework/aop/framework/AdvisedSupport;
    //   193: astore 8
    //   195: aload_0
    //   196: aload_2
    //   197: aload_0
    //   198: aconst_null
    //   199: aconst_null
    //   200: aconst_null
    //   201: invokevirtual 73	com/taobao/txc/client/aop/TxcTransactionScaner:getAdvicesAndAdvisorsForBean	(Ljava/lang/Class;Ljava/lang/String;Lorg/springframework/aop/TargetSource;)[Ljava/lang/Object;
    //   204: invokevirtual 72	com/taobao/txc/client/aop/TxcTransactionScaner:buildAdvisors	(Ljava/lang/String;[Ljava/lang/Object;)[Lorg/springframework/aop/Advisor;
    //   207: astore 9
    //   209: aload 9
    //   211: astore 10
    //   213: aload 10
    //   215: arraylength
    //   216: istore 11
    //   218: iconst_0
    //   219: istore 12
    //   221: iload 12
    //   223: iload 11
    //   225: if_icmpge +24 -> 249
    //   228: aload 10
    //   230: iload 12
    //   232: aaload
    //   233: astore 13
    //   235: aload 8
    //   237: iconst_0
    //   238: aload 13
    //   240: invokevirtual 107	org/springframework/aop/framework/AdvisedSupport:addAdvisor	(ILorg/springframework/aop/Advisor;)V
    //   243: iinc 12 1
    //   246: goto -25 -> 221
    //   249: aload_1
    //   250: aload 4
    //   252: monitorexit
    //   253: areturn
    //   254: astore 14
    //   256: aload 4
    //   258: monitorexit
    //   259: aload 14
    //   261: athrow
    //   262: astore 4
    //   264: new 34	java/lang/RuntimeException
    //   267: dup
    //   268: aload 4
    //   270: invokespecial 92	java/lang/RuntimeException:<init>	(Ljava/lang/Throwable;)V
    //   273: athrow
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	274	0	this	TxcTransactionScaner
    //   0	274	1	paramObject1	Object
    //   0	274	2	paramString	String
    //   0	274	3	paramObject2	Object
    //   262	7	4	localException	Exception
    //   39	3	5	localClass	Class
    //   46	12	6	arrayOfMethod	Method[]
    //   55	100	7	localLinkedList	java.util.LinkedList
    //   59	177	8	localObject1	Object
    //   64	10	9	k	int
    //   207	3	9	arrayOfAdvisor1	org.springframework.aop.Advisor[]
    //   67	69	10	m	int
    //   211	18	10	arrayOfAdvisor2	org.springframework.aop.Advisor[]
    //   81	44	11	localMethod	Method
    //   216	10	11	n	int
    //   93	18	12	localTxcTransaction	TxcTransaction
    //   219	25	12	i1	int
    //   233	6	13	localAdvisor	org.springframework.aop.Advisor
    //   254	6	14	localObject2	Object
    // Exception table:
    //   from	to	target	type
    //   7	23	254	finally
    //   24	169	254	finally
    //   170	253	254	finally
    //   254	259	254	finally
    //   0	23	262	java/lang/Exception
    //   24	169	262	java/lang/Exception
    //   170	253	262	java/lang/Exception
    //   254	262	262	java/lang/Exception
  }
  
  private a a(Object paramObject, Method paramMethod)
  {
    TxcTransaction localTxcTransaction = (TxcTransaction)paramMethod.getAnnotation(TxcTransaction.class);
    return new a(localTxcTransaction, paramMethod);
  }
  
  private Class<?> a(Object paramObject)
  {
    if (AopUtils.isAopProxy(paramObject))
    {
      AdvisedSupport localAdvisedSupport = b(paramObject);
      Object localObject = localAdvisedSupport.getTargetSource().getTarget();
      return a(localObject);
    }
    return paramObject.getClass();
  }
  
  private AdvisedSupport b(Object paramObject)
  {
    Field localField1;
    if (AopUtils.isJdkDynamicProxy(paramObject)) {
      localField1 = paramObject.getClass().getSuperclass().getDeclaredField("h");
    } else {
      localField1 = paramObject.getClass().getDeclaredField("CGLIB$CALLBACK_0");
    }
    localField1.setAccessible(true);
    Object localObject = localField1.get(paramObject);
    Field localField2 = localObject.getClass().getDeclaredField("advised");
    localField2.setAccessible(true);
    return (AdvisedSupport)localField2.get(localObject);
  }
  
  protected Object[] getAdvicesAndAdvisorsForBean(Class paramClass, String paramString, TargetSource paramTargetSource)
  {
    return new Object[] { this.c };
  }
  
  public void onApplicationEvent(ApplicationEvent paramApplicationEvent)
  {
    if ((paramApplicationEvent != null) && ((paramApplicationEvent instanceof ContextRefreshedEvent)))
    {
      if (((ContextRefreshedEvent)paramApplicationEvent).getApplicationContext().getParent() != null) {
        a.info(paramApplicationEvent + " TxcTransactionScaner init, not root context");
      } else {
        a.info(paramApplicationEvent + " TxcTransactionScaner init, root context");
      }
      if (!this.j) {
        a();
      }
    }
  }
  
  public void setAccessKey(String paramString)
  {
    this.g = paramString;
  }
  
  public void setSecretKey(String paramString)
  {
    this.h = paramString;
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.client.aop.TxcTransactionScaner
 * JD-Core Version:    0.7.0.1
 */